package com.chuanyang.driverh.mainorder.adapter;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.chuanyang.driverh.R;
import com.chuanyang.driverh.responseresult.LookWaybillData;
import com.chuanyang.driverh.utils.BitmapUtil;

import java.util.List;

public class OrderDriverAdapter extends BaseAdapter {

    private List<LookWaybillData.DataBean> orderDirverEntityList;
    private LayoutInflater mInflater;
    private Context mContext;
    private int status;

    public void setOrderDirverEntityList(List<LookWaybillData.DataBean> orderDirverEntityList) {
        this.orderDirverEntityList = orderDirverEntityList;
        notifyDataSetChanged();
    }

    public OrderDriverAdapter(Context activity, List<LookWaybillData.DataBean> orderDirverEntities) {
        orderDirverEntityList = orderDirverEntities;
        mContext = activity;
        mInflater = LayoutInflater.from(activity);
    }

    @Override
    public int getCount() {
        return orderDirverEntityList.size();
    }

    @Override
    public Object getItem(int position) {
        return orderDirverEntityList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.order_item_driver_list, null);
            holder = new ViewHolder();
            holder.iv_driver_photo = (ImageView) convertView.findViewById(R.id.iv_driver_photo);
            holder.rb_stars = (RatingBar) convertView.findViewById(R.id.rb_stars);
            holder.tv_driver_name = (TextView) convertView.findViewById(R.id.tv_driver_name);
            holder.tv_driver_number = (TextView) convertView.findViewById(R.id.tv_driver_number);
            holder.tv_driver_order_number = (TextView) convertView.findViewById(R.id.tv_driver_order_number);
            holder.tv_waybill_status = (TextView) convertView.findViewById(R.id.tv_waybill_status);
            holder.tv_driver_waybillweight = (TextView) convertView.findViewById(R.id.tv_driver_waybillweight);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        //holder.tv_goods_name_modification.setText(goodsEntities.get(position).getGoodsName());
        //跳转到显示地图的界面
        LookWaybillData.DataBean  bean=orderDirverEntityList.get(position);
        BitmapUtil.showImgForNetPath(bean.getUserImage(), holder.iv_driver_photo);
        holder.tv_driver_name.setText(bean.getDriverName());
        holder.tv_driver_number.setText(bean.getPlateNumber());
        holder.tv_driver_order_number.setText(bean.getWaybillNo());
        holder.rb_stars.setRating(bean.getStar());
        holder.tv_driver_waybillweight.setText(bean.getWeight()+"t");
        try {
            status = bean.getWaybillStatus();
        } catch (Exception e)
        {
            status = -1;
        }

        if (status < 0) {
            holder.tv_waybill_status.setText("运单异常");
        }
        else if (bean.getWaybillStatus()==0) {
            holder.tv_waybill_status.setText("初始化");
        } else if (bean.getWaybillStatus()==2) {
            holder.tv_waybill_status.setText("待装货");
        } else if (bean.getWaybillStatus()==3) {
            holder.tv_waybill_status.setText("装货中");
        } else if (bean.getWaybillStatus()==4) {
            holder.tv_waybill_status.setText("运输中");
        } else if (bean.getWaybillStatus()==5) {
            holder.tv_waybill_status.setText("卸货中");
        } else if (bean.getWaybillStatus()==6) {
            holder.tv_waybill_status.setText("待确认收货");
        }
        else if (bean.getWaybillStatus()==7) {
            holder.tv_waybill_status.setText("已完成");
        }

        return convertView;
    }

    public class ViewHolder {
        public ImageView iv_driver_photo;
        public RatingBar rb_stars;
        public TextView tv_driver_name;
        public TextView tv_driver_number;
        public TextView tv_driver_order_number;
        public TextView tv_waybill_status;
        public TextView tv_driver_waybillweight;
    }
}
